﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using Microsoft.Xna.Framework;
//using Microsoft.Xna.Framework.Graphics;
//using Microsoft.Xna.Framework.Content;
//using Kaleta.Network;

//namespace StarWarsGame
//{
//    public class Laserbolt : DistributableObject
//    {             



//            public void setup_and_fire(Vector3 fstart, Vector3 fDirection, Color fcolor, float speed, bool randoms)//, Matrix startRotation)
//            {
//                whichbolt++;
//                if (whichbolt == 200) whichbolt = 0;  // only allows 20 laserbolts at a time, usually that is plenty.

//                bolt[whichbolt].start_position = fstart;

//                bolt[whichbolt].bolt_speed = speed;
//                bolt[whichbolt].color = fcolor;
//                bolt[whichbolt].alive = true;

//                if (randoms) // adds some random noise to the direction
//                {
//                    bolt[whichbolt].direction.X = fDirection.X + (float)(random_number.Next(100) - 50) / 10000f;
//                    bolt[whichbolt].direction.Y = fDirection.Y + (float)(random_number.Next(100) - 50) / 10000f;
//                    bolt[whichbolt].direction.Z = fDirection.Z + (float)(random_number.Next(100) - 50) / 10000f;

//                }
//                else
//                {
//                    bolt[whichbolt].direction = fDirection;
//                }


//                bolt[whichbolt].world_matrix = Matrix.Identity * Matrix.CreateTranslation(fstart);

//                bolt[whichbolt].direction.Normalize();

//            }

//            public class bolt_manager
//            {
//                public Matrix world_matrix = Matrix.Identity;
//                public Vector3 center_to_viewer,
//                               work_vector,
//                               direction,
//                               trans_save;


//                public bool alive = false;

//                public float bolt_speed = 0;
//                public float distance_travelled;

//                public Vector3 start_position;
//                public Color color = Color.CornflowerBlue;


//                public void update()
//                {
//                    if (alive)
//                    {
//                        #region move the world matrix

//                        distance_travelled = Vector3.Distance(start_position, world_matrix.Translation);

//                        if (distance_travelled < 15) // set a maximum allowable distance here
//                        {
//                            //  world_matrix.Translation += direction * bolt_speed;

//                        }
//                        else
//                        {
//                            alive = false;

//                        }


//                        // you will need to setup some collision detection somewhere to kill the bolt on impact

//                        world_matrix.Translation += direction * bolt_speed;

//                        work_vector = world_matrix.Translation;

//                        work_vector.Normalize();
//                        // - work_vector is camera to laser direction                 

//                        // work vector will be used to calculate the orientation of the laserbolt.

//                        #endregion


//                        #region build the world matrix

//                        world_matrix.Forward = direction;

//                        world_matrix.Up = Vector3.Normalize(Vector3.Cross(world_matrix.Forward, -work_vector));

//                        world_matrix.Right = Vector3.Normalize(Vector3.Cross(world_matrix.Forward, world_matrix.Up));
//                        center_to_viewer = world_matrix.Up; // will find right & left in the shader

//                        #endregion
//                    }
//                }


//            }//end bolt manager


//            public bolt_manager[] bolt = new bolt_manager[200];// this will be an array of bolts



//            public void load_and_assign_effects(ContentManager content, string filename, Effect effect)
//            {
//                core = content.Load<Model>(filename);
//                foreach (ModelMesh mesh in core.Meshes)
//                    foreach (ModelMeshPart part in mesh.MeshParts)
//                        part.Effect = effect;

//                effect_color = effect.Parameters["laser_bolt_color"];
//                effect_center_to_viewer = effect.Parameters["center_to_viewer"];
//                effect_technique = effect.Techniques["laserbolt_technique"];
//                effect_matrices_combined = effect.Parameters["world_matrices"];

//                for (int i = 0; i < 200; i++)
//                {
//                    bolt[i] = new bolt_manager();
//                    bolt[i].world_matrix = Matrix.Identity;
//                }

//            }

//            public void draw(Matrix view, Matrix projection, GraphicsDevice gd, Effect effect)
//            {
//                effect.CurrentTechnique = effect_technique;

//                for (i = 0; i < 200; i++)
//                    if (bolt[i].alive)
//                    {
//                        Matrix worldMatrix = Matrix.CreateScale(0.0300f, 0.0300f, 0.1000f) * bolt[i].world_matrix;
//                        shader_matrices_combined[0] = worldMatrix;
//                        shader_matrices_combined[1] = worldMatrix * view * projection;

//                        effect_matrices_combined.SetValue(shader_matrices_combined);

//                        effect_color.SetValue(bolt[i].color.ToVector4());

//                        effect_center_to_viewer.SetValue(bolt[i].center_to_viewer);

//                        core.Meshes[0].Draw();
//                    }

//            }         



//        public Laserbolt()
//        {
//            _rotationDistributable = DistributableProperty<Quaternion>.Register("laserboltRotation", this);
//            _positionDistributable = DistributableProperty<Vector3>.Register("laserboltPosition", this);
//            _ownerDistributable = DistributableProperty<int>.Register("laserboltOwner", this);
        
//        }

//        private DistributableProperty<Quaternion> _rotationDistributable;
//        private DistributableProperty<Vector3> _positionDistributable;
//        private DistributableProperty<int> _ownerDistributable;

//        public Vector3 laserboltPosition { get; set; }
//        public Quaternion laserboltRotation { get; set; }
//        public int laserboltOwner { get; set; }
 
//        public Quaternion locRotation
//        {
//            get
//            {
//                return _rotationDistributable.GetValue();
//            }
//            set
//            {
//                _rotationDistributable.SetValue(value);
//            }
//        }      
//        public Vector3 locPosition
//        {
//            get
//            {
//                return _positionDistributable.GetValue();
//            }
//            set
//            {
//                _positionDistributable.SetValue(value);
//            }
//        }
//        public int locOwner
//        {
//            get
//            {
//                return _ownerDistributable.GetValue();
//            }
//            set
//            {
//                _ownerDistributable.SetValue(value);
//            }
//        }
     
//    }
 
//}
